%% FUNCTION: calcFuelWeightFraction
% Function that calculates the fraction of the fuel weight in relation to
%   the MTOW, according to the engine
%   
% INPUT:
%   engine:
%       type [int]: 1 for 1 single engine, 2 for twin engine, 3 for
%           business jet
%       sfcLoiter [int, ]: 
%       sfcCriuse [int, ]: 
%   extraFuel [%]: porcentage of extra fuel
%   requirementsSpecification:
%       range [int, nm]:
%       loiterDuration [int, h]:
%       cruiseSpeed [int, ktas]:
% OUTPUT:
%   fuelWeightFraction:
%
% AUTHOR: Renato Honda
% REVISION: 1
%

function [fuelWeightFraction] = calcFuelWeightFraction ( aircraft, engines, extraFuel )

% variables from the input
range = aircraft.range;
cruiseSpeed = aircraft.cruiseSpeed;
loiterDuration = aircraft.loiterDuration;
ldMax = aircraft.ldMax;
ldCruise = aircraft.ldCruise;
sfcLoiter = engines(aircraft.idEngine).sfcLoiter;
sfcCruise = engines(aircraft.idEngine).sfcCruise;

% Mission fraction:
%   w1w0: warming up, taxi and take-off
%   w2w1: climbing
%   w3w2: cruise
%   w4w3: loiter
%   w5w4: descend and landing

switch engines(aircraft.idEngine).type
    case 1  % single engine (ref. Roskan)
        w5w4 = 0.993 * 0.993;
        w2w1 = 0.992;
        w1w0 = 0.995 * 0.997 * 0.998;
        sfcCruise = sfcCruise * aircraft.cruiseSpeed / ( 603.5 * engines(aircraft.idEngine).np );
        sfcLoiter = sfcCruise;
    case 2  % twin engines (ref. Roskan)
        w5w4 = 0.992 * 0.992;
        w2w1 = 0.99;
        w1w0 = 0.992 * 0.996 * 0.996;
        sfcCruise = sfcCruise * aircraft.cruiseSpeed / ( 603.5 * engines(aircraft.idEngine).np );
        sfcLoiter = sfcCruise;
    case 3  % business jet (ref. Roskan)
        w5w4 = 0.99 * 0.992;
        w2w1 = 0.98;
        w1w0 = 0.99 * 0.995 * 0.995;
    otherwise
end

w4w3 = exp( -sfcLoiter * loiterDuration / (ldMax) );
w3w2 = exp( -sfcCruise * range / (cruiseSpeed * ldCruise) );

fuelWeightFraction = ( 1 - (w5w4 * w4w3 * w3w2 * w2w1 * w1w0) ) * ( 1 + extraFuel );

return